package book;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Random;
import java.util.Scanner;
import java.util.Set;

public class BookStore {
    static Book [] books = new Book[7];
    static {
        books [0] = new Book(1,"红楼梦",51.0,30);
        books [1] = new Book(2,"新华字典",51.5,30);
        books [2] = new Book(3,"西游记",55.0,30);
        books [3] = new Book(4,"Java基础",60.0,30);
        books [4] = new Book(5,"三国志",40.0,30);
        books [5] = new Book(6,"火影忍者",45.0,30);
        books [6] = new Book(7,"流浪地球",32.0,30);
    }
    public static void main(String[] args) {
        showBook(books);
        Person p1 = new Person("zhangsan");
        HashMap<Book, Integer> book = p1.buyBooks(books);
        count(book,p1);
//
    }

    private static void showBook(Book[] books) {
        System.out.println("编号\t图书名称\t图书价格\t库存数量");
        for(int i = 0;i<books.length;i++){
            System.out.println(books[i].getId()+"\t"+books[i].getName()+"\t"+books[i].getPrice()+"\t"+books[i].getStorage());
        }
    }
//    private static void showTotal(Book book,Person p){
//        Scanner sc = new Scanner(System.in);
//        System.out.println("请输入购买数量：");
//        int num = sc.nextInt();
//        double total = book.getPrice() * num;
//        Random random = new Random();
//        int orderNum = random.nextInt();
//        System.out.println("订单编号："+Math.abs(orderNum));
//        System.out.println("购物时间："+LocalDateTime.now());
//        System.out.println("会员："+p.getName());
//        System.out.println("图书名称："+book.getName()+"\t单价："+book.getPrice());
//    }
    public static void count(HashMap<Book,Integer> bookList,Person p1){
        double total = 0;
        Set<Book> set = bookList.keySet();
        Random random = new Random();
        int orderNum = random.nextInt();
        System.out.println("订单编号："+Math.abs(orderNum));
        System.out.println("购物时间："+LocalDateTime.now());
        System.out.println("会员："+p1.getName());
        for(Book book:set){
            int number = bookList.get(book);
            total+= book.getPrice() * number;
            System.out.println(book.getName()+",单价："+book.getPrice()+",购买数量："+number);

        }
        System.out.println("------------------------------------------------------------");
        System.out.println("\t\t总计："+total);
    }
}
